<template>
  <div>
    <!--二次索赔结算 -->
    <TopFilter ref="TopFilterss" :list="topFilterList" :cols="3" :collapse="collapse" labelWidth="120" @filterChange="changeHandle" ></TopFilter>
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'records'"
      :onColumnsChange="(columns) => (this.columns = columns)"
      :is-select-column="false"
      columnsRef="ClaimAccessoryAccountSummary"
    >
      <template slot="controls" slot-scope="props">
        <multiuse-button size="small" type="primary" :click="exportFileBtn.bind()">导出</multiuse-button>
        <multiuse-button size="small" type="primary" :click="statement.bind()">结算</multiuse-button>
      </template>
    </FilterTable>
    <BaseDialog :visible.sync="suppliers" :title="'供应商选择'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <supplier @close="suppliersClose" @save="suppliersSave" :rowDate="rowDate"></supplier>
    </BaseDialog>
  </div>
</template>
<script>
import { getListByPage, getSecondClaimSettleExport, settleAccounts } from '@/api/claim/factory/SecondClaimSettle';
import { exportExcelFile, notifyAction } from '@/utils/index';
import { dictionary } from '@/utils/dictMixin';
import supplier from '@/pages/repair/repairBusiness/supplierInformation/supplier.vue';

export default {
  mixins: [dictionary],
  components: { supplier },
  data() {
    return {
      dataList: [],
      rowData: {},
      visible: false,
      detailFlag: false,
      editFlag: false,
      collapse: false,
      infoId: null,
      fetchapi: getListByPage,
      topFilterList: this.topFilterListFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchParams: {}, //ipa 接口
      formData: [],
      suppliers: false,
      responsibleCode: null
    };
  },
  methods: {
    //搜索数据
    topFilterListFun() {
      return [
        { type: 'INPUT', label: '索赔单号', fieldName: 'claimNo', placeholder: '请输入索赔单号...', initialValue: '' },
        {
          type: 'INPUT',
          label: '供应商',
          fieldName: 'responsiblePerson',
          readonly: true,
          placeholder: '请选择供应商...',
          rules: [{ required: false, message: '请选择供应商', trigger: 'blur' }],
          unitRender: (p) => {
            return (
              <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.selectResponsibleCode()} />
              </div>
            );
          },
        },
        { type: 'SELECT', label: '索赔类型', fieldName: 'cmsClaimType', placeholder: '请选择', initialValue: '', itemList: this.createDictList(5510, [55101006, 55101007, 55101008, 55101009]) },
        { type: 'SELECT', label: '是否二次结算', fieldName: 'isSupSettle', placeholder: '请选择', initialValue: '', itemList: this.createDictList(1004) },
        { type: 'INPUT', label: '结算单号', fieldName: 'settleNo', placeholder: '请输入结算单号...', initialValue: '' },
        { type: 'INPUT', label: '结算月份', fieldName: 'settleMonth', placeholder: '请输入结算月份例如:202211...', initialValue: '' },
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          fixed: 'left',
          sorter: true,
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        { title: '索赔单号', dataIndex: 'claimNo', sorter: true, width: 180 },
        { title: '是否二次结算', dataIndex: 'isSupSettle', sorter: true, width: 130, dictItems: this.createDictList(1004) },
        { title: '结算单号', dataIndex: 'settleNo', sorter: true },
        { title: '供应商代码', dataIndex: 'responsibleCode', sorter: true },
        { title: '供应商名称', dataIndex: 'responsiblePerson', sorter: true, width: 180 },
        { title: '索赔类型', dataIndex: 'cmsClaimType', sorter: true, dictItems: this.createDictList(5510) },
        { title: '结算月份', dataIndex: 'settleMonth', sorter: true },
        { title: '主损件代码', dataIndex: 'partCode', sorter: true },
        { title: '主损件名称', dataIndex: 'partName', sorter: true },
        { title: '故障现象描述', dataIndex: 'faultAppear', sorter: true },
        { title: '故障原因描述', dataIndex: 'faultReason', sorter: true },
        { title: '维修方案描述', dataIndex: 'cmsClaimPgm', sorter: true },
        { title: '处理结果描述', dataIndex: 'handleResult', sorter: true },
        { title: '备注', dataIndex: 'remark', sorter: true },
        { title: '核定材料费', dataIndex: 'approvedPartAmount', sorter: true, precision: 2 },
        { title: '核定工时费', dataIndex: 'labourAmount', sorter: true, precision: 2 },
        { title: '核定附加费', dataIndex: 'addAmount', sorter: true, precision: 2 },
        { title: '核定外出救援费', dataIndex: 'helpAmount', sorter: true, precision: 2 },
        { title: '核定管理费', dataIndex: 'approvedPtManageAmount', sorter: true, precision: 2 },
        { title: '小计', dataIndex: 'subtotal', sorter: true, precision: 2 },
        { title: '追偿费用', dataIndex: 'totalAmount', sorter: true, precision: 2 },
        { title: '服务中心代码', dataIndex: 'dealerCode', sorter: true },
        { title: '服务中心简称', dataIndex: 'dealerShortname', sorter: true, width: 150 },
        { title: '车型名称', dataIndex: 'modelName', sorter: true, width: 80 },
        { title: 'VIN', dataIndex: 'vin', sorter: true },
        { title: '车牌号', dataIndex: 'licenseNo', sorter: true },
        { title: '发动机号', dataIndex: 'engineNo', sorter: true },
        { title: '电机号', dataIndex: 'motorNo', sorter: true, width: 180 },
        { title: '进厂日期', dataIndex: 'serviceBeginDate', sorter: true, width: 150 },
        { title: '生产日期', dataIndex: 'prodDate', sorter: true, width: 150 },
        { title: '保修开始日期', dataIndex: 'repairBeginDate', sorter: true, width: 150 },
        { title: '表显里程', dataIndex: 'driveMile', sorter: true },
        { title: '电池包编号', dataIndex: 'batteryNo', sorter: true },
      ];
    },
    changeHandle(val) {
      console.log('val', val);
      if (val.responsiblePerson) {
        val.responsibleCode = this.responsibleCode;
      }else{
        val.responsibleCode = null;
      }
      this.fetchParams = Object.assign({}, val);
    },
    async exportFileBtn() {
      await getSecondClaimSettleExport(this.fetchParams).then((res) => {
        console.log(res);
        if (res.status !== 'failure') {
          exportExcelFile(res.data, '二次索赔结算信息');
        } else {
          notifyAction('导出失败', 'error');
        }
      });
    },
    async statement() {
      await settleAccounts({isSupSettle: 10041002}).then((res) => {
        if (res.resultCode === 200) {
          this.$notify.success({ type: '提示信息', message: '结算成功!!' });
        } else {
          if (res.data != null) {
            this.formData = res.data;
            this.visible = true;
          }
        }
      });
      this.fetchParams = Object.assign({});
    },
    close() {
      this.visible = false;
      this.fetchParams = Object.assign({}, val);
    },
    //供应商选择
    selectResponsibleCode() {
      this.suppliers = true;
    },
    suppliersSave(obj) {
      this.topFilterList.find((x) => x.fieldName == 'responsiblePerson').initialValue = obj[0].supplierName;
      this.responsibleCode = obj[0].supplierCode;
      this.suppliersClose();
    },
    suppliersClose() {
      this.suppliers = false;
    },
  },
};
</script>
<style lang="less" scoped></style>

